<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="/css/common.css" />
		<link rel="stylesheet" type="text/css" href="/js/flatpickr.min.css" />
		<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.7/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="/dialog/css/dialog.css" />
		<link rel="stylesheet" type="text/css" href="/css/font-awesome.css" />
	</head>

	<body>
		<!--顶部导航 -->
		<nav class="topNavItemBox">
			<div id="ItemBox">
				<div class="title">肉品溯源管理系统</div>
			</div>
		</nav>
		<!-- 左侧导航 -->
		<#include "left.ftl"/>
        <div class="page_main">
			<h3>屠宰包装</h3> <span class="add_link"><a href="slaughterAdd.ftl">新增产品信息></a></span>
			<div class="page_content">
				<h4>产品信息查询</h4> 
				<br />
				<form id="slaughter_query" method="post" action="ProductAction_getProByCondiction">
					<label style="width:100px">产品编号</label><input type="text" name="productID" class="commonInputtext" /><span></span>
					<label style="width:100px">生猪编号</label><input type="text" name="animalID" class="commonInputtext" /><span></span>
					<label style="width:120px">养殖场编号</label><input type="text" name="compID" class="commonInputtext" />
					<br />
					<label style="width:100px">追溯码</label><input type="text" name="tracecode" class="commonInputtext" /><span></span>
					<label style="width:100px">类型编号</label><input type="text" name="typeID" class="commonInputtext" />
					
					<input type="submit" value="查询" style="display: inline-block; margin-left: 320px;" />
				</form>
				<div>
					<table id="slaughter_table" class="table" width="100%">
						<thead>
							<tr>
								<th><input id="checkall" type="checkbox" /></th>
								<th width="30"></th>
								<th width="100">产品编号</th>
								<th width="150">追溯码</th>
								<th width="150">生猪编号</th>
								<th width="150">生产企业编号</th>
								<th width="150">产品类型编号</th>
								<th width="150">检验结果</th>
								<th width="150">检验时间</th>
								<th width="100">销售商家</th>
								<th width="150">生产时间</th>
								<th width="80"></th>
								<th width="150"></th>
							</tr>
						</thead>
						<tbody>
							<tr id="no_data">
								<td></td>
								<td></td>
								<td></td>
								<td>暂无数据</td>
									<!--<a href="">编辑</a>/<a href="">删除</a>-->
								</td>
							</tr>
						</tbody>
					</table>
				</div>
				<input type="button" id="deleteAllchoice" value="删除所选" style="display: none;" />
				<div id="barcon" name="barcon" style="margin-left: 200px;font-size:10px"></div>
			</div>
			<div class="footer">
				<div class="footer_lineone">
					<span id="logo"></span>肉品溯源管理系统 
					<span class="footer_lineoneSpan"><a href="aboutus.html">关于我们</a></span>
					<span class="footer_lineoneSpan"><a target="_blank" href="http://www.cfsiw.com/">食品安全信息</a></span> 
					<span class="footer_lineoneSpan"><a href="suggestionAdd.ftl">联系我们</a></span>
				</div>
				<div class="footer_linetwo">
					 &copy;2017广东技术师范学院
				</div>
			</div>
		</div>

		<script src="/js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/js/google-maps.js" type="text/javascript" charset="utf-8"></script>
		<script src="/js/jquery.form.js"></script>
		<script src="/dialog/js/dialog.js"></script>
		<script src="/js/jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/js/messages_zh.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/js/common.js"></script>
		<script src="/js/flatpickr.js">
		</script>
		<script type="text/javascript" charset="UTF-8">
			$(function() {
				//初始化侧边栏
				$(".vertical-nav").verticalnav({
					speed: 400,
					align: "left"
				});
				
				//初始化时间
				$("#slaughter_date").flatpickr();

				var re_data; //每次传过来的数据
				//查询
				$("#slaughter_query").ajaxForm(function(data) {
					console.log(data);
					re_data = data;
					$("#slaughter_table tbody tr").remove();
					for(var i = 0; i < data.length; i++) {
						var no = i+1;
						var tb = $("#slaughter_table tbody");
						var td1 = '<td><input type="checkbox" name="selectRows" class="isCheck" value="' + data[i].productId + '"/></td>';
						var td2 = '<td>' + no + '</td>';
						var td3 = '<td>' + data[i].productId + '</td>';
						var td4 = '<td>' + data[i].traceCode + '</td>';
						var td5 = '<td>' + data[i].purchaseInfo.gid + '</td>';
						var td6 = '<td>' + data[i].companyInfo.gid + '</td>';
						var td7 = '<td>' + data[i].producetypeLnfo2.gid + '</td>';
						var td8 = '<td>' + data[i].inspectResult + '</td>';
						if(data[i].inspectTime!=null){
							var td9 = '<td>' + data[i].inspectTime.slice(0,10) + '</td>';
						}else{
							var td9 = '<td>暂无数据</td>';
						}
						
						var td10 = '<td>' + data[i].salerName + '</td>';
						if(data[i].selledTime!=null){
							var td11 = '<td>' + data[i].processTime.slice(0,10) + '</td>';
						}else{
							var td11 = '<td>暂无数据</td>';
						}
						/* var td12 = '<td>' + data[i].procAmount + '</td>';
						var td13 = '<td>' + data[i].procUnit + '</td>';
						if(data[i].selledTime!=null){
							var td14 = '<td>' + data[i].selledTime.slice(0,10) + '</td>';
						}else{
							var td14 = '<td>暂无数据</td>';
						} */
						var td15 = '<td><input type="button" onclick="moreInfo(' + i + ')" value="更多信息" ></td>';
						var td16 = '<td><input type="button" onclick="updateData(' + i + ')" class="change" value="更改" style="padding:0 5px"/><input type="button" value="删除" onclick="deleteData(' + data[i].productId + ')" style="padding:0 5px" /></td>'
						var tr_add = '<tr id="slaughter_row' + data[i].productId + '">' + td1 + td2 + td3 + td4 + td5 + td6 + td7 + td8 + td9 + td10+ td11 + td15 + td16 + '</tr>'
						tb.append(tr_add);
					}
					$("#no_data").remove();
					$("#deleteAllchoice").css("display", "block");
					goPage(1, 4, "slaughter_table");
				});
				
				
				//更多信息
				 moreInfo = function(i) {
					var diaRow1 = '<div><label class="dialog_label">产品编号</label><span class="dialog_label">' + re_data[i].productId + '</span></div>';
					//var diaRow2 = '<div><label class="dialog_label">产品追溯码</label><span class="dialog_label">' + re_data[i].traceCode + '</span></div>';
					//var diaRow3 = '<div><label class="dialog_label">生猪编号</label><span class="dialog_label">' + re_data[i].purchaseInfo.gid + '</span></div>';
					//var diaRow4 = '<div><label class="dialog_label">生产企业编号</label><span class="dialog_label">' + re_data[i].companyInfo.gid + '</span></div>';
					//var diaRow5 = '<div><label class="dialog_label">产品类型编号</label><span class="dialog_label">' + re_data[i].producetypeLnfo.gid + '</span></div>';
					/* if(re_data[i].processTime!=null){
						var diaRow6 = '<div><label class="dialog_label">生产时间</label><span class="dialog_label">' + re_data[i].processTime.slice(0,10)+ '</span></div>';
					}else{
						var diaRow6 = '<div><label class="dialog_label">生产时间</label><span class="dialog_label">暂无日期</span></div>';
					} */
					var diaRow7 = '<div><label class="dialog_label">生产人员编号</label><span class="dialog_label">' + re_data[i].processerCode + '</span></div>';
					//var diaRow8 = '<div><label class="dialog_label">检验结果类型</label><span class="dialog_label">' + re_data[i].inspectResultCode + '</span></div>';
					//var diaRow9 = '<div><label class="dialog_label">检验结果</label><span class="dialog_label">' + re_data[i].inspectResult + '</span></div>';
					/* if(re_data[i].inspectTime!=null){
						var diaRow10 = '<div><label class="dialog_label">检验时间</label><span class="dialog_label">' + re_data[i].inspectTime.slice(0,10) + '</span></div>';
					}else{
						var diaRow10 = '<div><label class="dialog_label">检验时间</label><span class="dialog_label">暂无数据</span></div>';
					} */
					var diaRow11 = '<div><label class="dialog_label">检验台编号</label><span class="dialog_label">' + re_data[i].inspecterCode + '</span></div>';
					var diaRow12 = '<div><label class="dialog_label">商家编号</label><span class="dialog_label">' + re_data[i].salerlD + '</span></div>';
					var diaRow13 = '<div><label class="dialog_label">商家名称</label><span class="dialog_label">' + re_data[i].salerName + '</span></div>';
					var diaRow14 = '<div><label class="dialog_label">终端编号</label><span class="dialog_label">' + re_data[i].balancelD + '</span></div>';
					var diaRow15 = '<div><label class="dialog_label">终端编码</label><span class="dialog_label">' + re_data[i].balanceCode + '</span></div>';
					var diaRow16 = '<div><label class="dialog_label">产品单价</label><span class="dialog_label">' + re_data[i].procPrice + '</span></div>';
					var diaRow17 = '<div><label class="dialog_label">产品单位</label><span class="dialog_label">' + re_data[i].procUnit + '</span></div>';
					var diaRow18 = '<div><label class="dialog_label">产品数量</label><span class="dialog_label">' + re_data[i].procAmount + '</span></div>';
					var diaRow19 = '<div><label class="dialog_label">产品计价</label><span class="dialog_label">' + re_data[i].procCount + '</span></div>';
					var diaRow20 = '<div><label class="dialog_label">计价折扣</label><span class="dialog_label">' + re_data[i].procDiscount + '</span></div>';
					var diaRow21 = '<div><label class="dialog_label">出售价格</label><span class="dialog_label">' + re_data[i].sellPrice + '</span></div>';
					if(re_data[i].selledTime!=null){
						var diaRow22 = '<div><label class="dialog_label">出售日期</label><span class="dialog_label">' + re_data[i].selledTime.slice(0,10) + '</span></div>';
					}else{
						var diaRow22 = '<div><label class="dialog_label">出售日期</label><span class="dialog_label">暂无日期 </span></div>';
					}
	
					var dia_add = diaRow1  + diaRow7  + diaRow11 + diaRow12 + diaRow13 +diaRow14 + diaRow15 + diaRow16+ diaRow17+ diaRow18+ diaRow19+ diaRow20+ diaRow21+ diaRow22;
					$.dialog({
						contentHtml: dia_add
					});
				}
				
				

				//多选
				$("#checkall").click(function() {
					$('input[class="isCheck"]').attr("checked", this.checked);
				});
				var $isCheck = $("input[class='isCheck']");
				$isCheck.click(function() {
					$("#checkall").attr("checked", $isCheck.length == $("input[class='isCheck']:checked").length ? true : false);
				});

				//删除

				function deleteByids(delete_data) {
					$.dialog({
						type: 'confirm',
						contentHtml: '<p style:"magrin:0 auto">确认删除？</p>',
						onClickOk: function() {
							$.ajax({
								url: "ProductAction_delectProduct",
								data: {
									'selectRows': delete_data
								},
								success: function(data) {
									console.log(data);
									var chrstr = delete_data.split(",");
									console.log(chrstr);
									console.log($("#slaughter_row" + chrstr[0]));
									for(i = 0; i < chrstr.length; i++) {
										$("#slaughter_row" + chrstr[i]).remove();
									}
								}
							});
						}
					});

				}
				deleteData = function(i) {
					var st = i;
					st += ",";
					deleteByids(st);
				}
				$("#deleteAllchoice").click(function() {
					delete_data = get_checkbox_data();
					deleteByids(delete_data);
				});

				function get_checkbox_data() {
					var data_temp = "";
					$("input[class='isCheck']:checked").each(function() { // 遍历选中的checkbox
						data_temp += $(this).val() + ',';
						console.log(data_temp);
					});;
					return data_temp;

				}

				//更改

				updateData = function(i) {
					var row0 = '<form id="slaughter_updateform" action="ProductAction_updateProduct" method="post">'
					var row1 = '<li><label class="labelBeforinput">产品编号</label><input type="text" class="bigInputtext" name="productId" readonly="true" value="' + re_data[i].productId + '" /></li>';
					var row2 = '<li><label class="labelBeforinput">生猪编号</label><input name="purchaseInfo.gid" class="bigInputtext" readOnly="true" type="text" value="' + re_data[i].purchaseInfo.gid + '" /></li>';
					var row3 = '<li><label class="labelBeforinput">生产时间</label><input name="processTime" id="productTime" data-date-format="Y-m-d" class="bigInputtext" type="text" value="' + re_data[i].processTime + '" /></li>';
					var row4 = '<li><label class="labelBeforinput">生产人员编号</label><input name="processerCode" class="bigInputtext" type="text" value="' + re_data[i].processerCode + '" /></li>';
					var row5 = '<li><label class="labelBeforinput">检验结果类型</label><input name="inspectResultCode" class="bigInputtext" type="text" value="' + re_data[i].inspectResultCode + '" /></li>';
					var row6 = '<li><label class="labelBeforinput">检验结果描述</label><input name="inspectResult" class="bigInputtext" type="text" value="' + re_data[i].inspectResult + '" /></li>';
					var row7 = '<li><label class="labelBeforinput">检验时间</label><input name="inspectTime" id="inspectTime" data-date-format="Y-m-d" class="bigInputtext" type="text" value="' + re_data[i].inspectTime + '" /></li>';
					var row8 = '<li><label class="labelBeforinput">检验台编号</label><input name="inspecterCode" class="bigInputtext" type="text" value="' + re_data[i].inspecterCode + '" /></li>';
					var row9 = '<li><label class="labelBeforinput">商家编号</label><input type="text" class="bigInputtext" name="salerlD"  value="' + re_data[i].salerlD + '" />';
					var row10 = '<li><label class="labelBeforinput">商家名称</label><input type="text"class="bigInputtext"  name="salerName" value="' + re_data[i].salerName + '" />';
					var row11 = '<li><label class="labelBeforinput">终端编号</label><input name="balancelD" class="bigInputtext"  type="text" value="' + re_data[i].balancelD + '" /></li>';
					var row12 = '<li><label class="labelBeforinput">终端编码</label><input class="bigInputtext" name="balanceCode" type="text" value="' + re_data[i].balanceCode + '" /></li>';
					var row13 = '<li><label class="labelBeforinput">产品单价</label><input name="procPrice" class="bigInputtext" type="text" value="' + re_data[i].procPrice + '" /></li>';
					var row14 = '<li><label class="labelBeforinput">产品单位</label><input name="procUnit" class="bigInputtext" type="text" value="' + re_data[i].procUnit + '" /></li>';
					var row15 = '<li><label class="labelBeforinput">产品重量</label><input name="procAmount" class="bigInputtext" type="text" value="' + re_data[i].procAmount + '" /></li>';
					var row16 = '<li><label class="labelBeforinput">产品计价</label><input name="procCount" class="bigInputtext" type="text" value="' + re_data[i].procCount + '" /></li>';
					var row17 = '<li><label class="labelBeforinput">计价折扣</label><input name="procDiscount" class="bigInputtext" type="text" value="' + re_data[i].procDiscount + '" /></li>';
					var row18 = '<li><label class="labelBeforinput">出售价格</label><input name="sellPrice" class="bigInputtext" type="text" value="' + re_data[i].sellPrice + '" /></li>';
					var row19 = '<li><label class="labelBeforinput">出售时间</label><input name="selledTime" id="selledTime" data-date-format="Y-m-d" class="bigInputtext" type="text" value="' + re_data[i].selledTime + '" /></li>';
					//追溯码
					var row20 = '<input type="hidden"class="bigInputtext"  name="traceCode" readonly="true" value="' + re_data[i].traceCode+ '" />';
					//生产企业编号
					var row21 = '<input class="bigInputtext" readonly="true" name="companyInfo.gid" type="hidden" value="' + re_data[i].companyInfo.gid + '" />';
					//产品类型编号
					var row22 = '<input name="producetypeLnfo2.gid" readonly="true" class="bigInputtext" type="hidden" value="' + re_data[i].producetypeLnfo2.gid + '" />';
					var row23 = '</form>'
					var str = row0 + row1 + row2 + row3 + row4 + row5 + row6 + row7 + row8 + row9 + row10 + row11 + row12+ row13+ row14 + row15 + row16 + row17 + row18 + row19 + row20+ row21+ row22 + row23;
					//console.log($("#slaughter_table"));

					$.dialog({
						type: 'confirm',
						titleText: '更改数据',
						contentHtml: str,
						onClickOk: function() {
							$("#slaughter_updateform").ajaxSubmit({
								type: 'post',
								success: function(data) {
									console.log(data);
									console.log(data.data.productId);
									var row = $("#slaughter_row" + data.data.productId);
									console.log(row);
									row.find("td").eq(2).text(data.data.productId);
									row.find("td").eq(3).text(data.data.traceCode);
									row.find("td").eq(4).text(data.data.purchaseInfo.gid);
									row.find("td").eq(5).text(data.data.companyInfo.gid);
									row.find("td").eq(6).text(data.data.producetypeLnfo2.gid);
									row.find("td").eq(7).text(data.data.inspectResult);
									row.find("td").eq(8).text(data.data.inspectTime.slice(0,10));
									row.find("td").eq(9).text(data.data.salerName);
									row.find("td").eq(10).text(data.data.processTime.slice(0,10));
/* 									row.find("td").eq(11).text(data.data.procAmount);
									row.find("td").eq(12).text(data.data.procUnit);
									row.find("td").eq(13).text(data.data.selledTime.slice(0,10)); */

									re_data[i] = data.data;
								}

							});
						}

					});
					//时间控制器
					$("#productTime").flatpickr();
					$("#inspectTime").flatpickr();
					$("#selledTime").flatpickr();
				}

			});
		</script>

	</body>

</html>